package susebs.pb.travel_server.utils;

import org.springframework.stereotype.Component;
import susebs.pb.travel_server.domain.Locations;
import susebs.pb.travel_server.entity.Users;

import java.util.Objects;

/**
 * 导航工具类
 */
@Component
public class NavigationUtil {

    /**
     * 获取用户城市字段
     */
    public static String getUserCity(Locations location) throws Exception {
        String res = "";
        //直接获取用户地址字符串
        String addr = location.getAddr();

        //如果获取不到，则根据用户定位（经纬度）重新解析
        if(Objects.equals(addr, "")){
            String addressResolution = MapInfoBasicUtil.addressResolution(location.getLng(), location.getLat());
            int starts = addr.indexOf("省");
            int ends = addr.indexOf("市");
            res = addressResolution.substring(starts + 1, ends + 1);
        }//否则直接解析
        else{
            int starts = addr.indexOf("省");
            int ends = addr.indexOf("市");
            res = addr.substring(starts + 1, ends + 1);
        }

        return res;
    }

}
